package com.midea.ai.air.ui.more.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.ui.more.fragment.MoreSettingAirExpertFragment;

import java.util.List;

/**
 * Created by hww on 2016/3/29.
 */
public class MoreSettingAirExpertAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private List<MoreSettingAirExpertFragment.air_expert_context> list;

    public MoreSettingAirExpertAdapter(Context context, List<MoreSettingAirExpertFragment.air_expert_context> list) {
        mInflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_more_air_expert, null);
            holder = new ViewHolder();
            holder.temp = (TextView) convertView.findViewById(R.id.item_more_air_expert_temp);
            holder.time = (TextView) convertView.findViewById(R.id.item_more_air_expert_time);
            holder.view_line = (View) convertView.findViewById(R.id.item_more_air_expert_line);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MoreSettingAirExpertFragment.air_expert_context air = list.get(position);

        holder.temp.setText(air.getTemp() + "℃");
        holder.time.setText(air.getTime() + "小时");

        if (position == (getCount() - 1)) {
            holder.view_line.setVisibility(View.GONE);
        } else {
            holder.view_line.setVisibility(View.VISIBLE);
        }

        return convertView;
    }


    class ViewHolder {
        private TextView temp;
        private TextView time;
        private View view_line;
    }
}
